//
// Description: 322. 零钱兑换
// Created by Loading on 2021/12/9.
//

#include <bits/stdc++.h>

using namespace std;

int coinChange(vector<int> &coins, int amount) {
    int n = coins.size();
    // 初始化dp数组，值为 amount + 1
    vector<int> dp(amount + 1, amount + 1);
    dp[0] = 0;
    for (int i = 1; i <= amount; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i - coins[j] >= 0) {
                dp[i] = min(dp[i], dp[i - coins[j]] + 1);
            }
        }
    }

    return dp[amount] > amount ? -1 : dp[amount];
}

int main() {
    vector<int> coins = {2};
    int amount = 3;
    int res = coinChange(coins, amount);
    cout << res << endl;

    return 0;
}